#!/bin/bash
if [ $# -lt 1 ]; then
   echo "please input :  func_no"
   exit
fi

func_no=$1

# hive tables
tmp_file=/tmp/func_hive_tables_$func_no.sql
cat >> $tmp_file << EOF
CREATE TABLE IF NOT EXISTS ACRM_TRANSACTION(CUSTOMER_ID STRING,TRAN_DATE STRING,TRAN_TYPE STRING, CHANNEL STRING, AMOUNT BIGINT) ROW FORMAT DELIMITED FIELDS TERMINATED BY ',' COLLECTION ITEMS TERMINATED BY '\n' STORED AS TEXTFILE;
CREATE TABLE IF NOT EXISTS ACRM_RFM(CACHE_ID STRING,CUSTOMER_ID STRING, R STRING, F STRING,  M STRING, RFM STRING)  STORED BY 'org.apache.hadoop.hive.hbase.hbasestoragehandler'  WITH SERDEPROPERTIES ("HBASE.COLUMNS.MAPPING"=":KEY,0:CUSTOMER_ID,0:R,0:F,0:M,0:RFM")  TBLPROPERTIES ("HBASE.TABLE.NAME" = "ACRM_RFM");
EOF

more $tmp_file

$HIVE_HOME/bin/hive -f "$tmp_file"

rm $tmp_file

# hbase tables by phoenix interface
tmp_file=/tmp/func_hbase_tables_$func_no.sql

cat >> $tmp_file << EOF
CREATE TABLE ACRM_RFM(CACHE_ID VARCHAR(30) primary key,CUSTOMER_ID VARCHAR(30),R VARCHAR(30), F VARCHAR(30),  M VARCHAR(30), RFM VARCHAR(30)) ;
EOF

more $tmp_file
.$PHOENIX_HOME/bin/sqlline.py localhost $tmp_file

rm $tmp_file